SQL using a function to check existence of event over a user id

join shbcf.ru